<template>
    <div class="wrapper">
        <top-header title="我的活动"></top-header>
        <list class="item-container"
                offset-accuracy="50px">
            <refresh @refresh="loadingDown(index)"></refresh>
            <cell class="border-cell"></cell>
            <cell v-for="(item,key) in activeList"
                    class="cell"
                    :key="key">
                <div class="list_content">
                    <div>
                        <text class="list_content_first">{{item.carname}}</text>
                        <div class="list_content_two">
                            <text class="list_content_two1">联系人：{{item.ownername}}</text>
                            <text class="list_content_two1">电话：{{item.ownerphone}}</text>
                        </div>
                        <div class="list_content_two">
                            <text class="list_content_two1">原价：{{item.carOriginalPrice}}W</text>
                            <text class="list_content_two1">已砍价：{{item.bargainPrice}}W</text>
                            <text class="list_content_two1">现价：{{item.carPrice}}W</text>
                        </div>
                    </div>
                </div>
                <div class="list_content_third">
                    <WxcButton @wxcButtonClicked="deleteActivity(item.id)" class="wxc_button_third" type="white" size="medium" text="删除"></WxcButton>
                </div>
            </cell>
            <cell class="cell fullC" v-if="activeList.length <= 0">
                <div class="no-order">
                    <text>暂无活动</text>
                </div>
            </cell>
            <loading class="loading" @loading="onloading(index)" :display="showLoading">
                <text class="indicator">加载中...</text>
            </loading>
        </list>
    </div>
</template>
<script>
import { WxcButton } from 'weex-ui';
import header from '../common/header'
export default {
    components: { 
        WxcButton,
        'top-header': header, 
    },
    data () {
        return {
            token: '',
            activeList: [],
            params: {
                uid: '',
                page: 1,
                limit: 15,
                sort: 'id',
                order: 'asc',
            },
            showLoading: 'hide',
            index: '',
        }
    },
    created () {
        let user = this.$storage.getSync('UserInfo')
        this.token = user.token
        this.params.uid = user.id
        this.getActivityList()
    },
    mounted () {
    },
    eros: {
        beforeBackAppear(params) {
            this.getActivityList()
        }
    },
    methods: {
        // 返回
        back () {
            this.$router.back();
        },
        callPhone (phone) {
            this.$coms.call(phone)
        },
        
        loadingDown(index) {
            this.getActivityList()
        },
        onloading(index) {
            // this.params.page = this.params.page + 1;
            // this.$notice.loading.show();
            this.showLoading = 'show';
            // if(!this.lastPage) {
            //     this.getActivityList();
            // } 
            setTimeout(() => {
                this.$notice.loading.hide();
                this.showLoading = 'hide'
            }, 600)
        },
        // 查询我的活动列表
        getActivityList () {
            this.$notice.loading.show();
            this.$fetch({
                method: 'POST',    // 大写
                name: 'bargain.bargainListByUid', //当前是在apis中配置的别名，你也可以直接绝对路径请求 如：url:http://xx.xx.com/xxx/xxx
                data: this.params
            }).then(resData => {
                // 成功回调
                this.isShowLoad = false;
                console.log('查询我的活动列表', JSON.stringify(resData.data))
                // this.$notice.toast({ message: resData.data})
                if(resData && resData.errno == 0){
                    this.activeList = resData.data
                }
                this.$notice.loading.hide();
            }, error => {
                // 错误回调
                this.isShowLoad = false;
                console.log(error)
                reject(error)
                // this.$notice.toast({ message: "登录失败, 请重试"})
            })
        },
        // 删除活动
        deleteActivity (id) {
            this.$fetch({
                method: 'POST',    // 大写
                name: 'bargain.deleteBargainListById', //当前是在apis中配置的别名，你也可以直接绝对路径请求 如：url:http://xx.xx.com/xxx/xxx
                data: {'id': id}
            }).then(resData => {
                // 成功回调
                this.isShowLoad = false;
                console.log(resData)
                // this.$notice.toast({ message: resData})
                if(resData && resData.errno == 0){
                    this.$notice.toast({ message: '删除成功'})
                    this.loadingDown()
                } else {
                    this.$notice.toast({ message: '删除失败'})
                }
            }, error => {
                // 错误回调
                this.isShowLoad = false;
                console.log(error)
            })
        },
    }
}
</script>
<style>
.iconfont {
    font-family: iconfont;
}
.wrapper{
    background-color: #fff;
}
.border-cell {
    background-color: #f2f3f4;
    width: 750px;
    height: 24px;
    align-items: center;
    justify-content: center;
    border-bottom-width: 1px;
    border-style: solid;
    border-color: #e0e0e0;
}
.cell{
    background-color: #fff;
    padding-bottom: 20px;
}
.list_content{
    flex-direction: row;
    margin-top: 30px;
    margin-bottom: 30px;
    margin-left: 20px;
    margin-right: 20px;
}
.list_content_first{
    color: #666;
    font-size: 30px;
    margin-left: 10px;
    margin-right: 10px;
    margin-bottom: 10px;
}
.list_content_two{
    flex-direction: row;
    margin-top: 20px;
    margin-bottom: 20px;
}
.list_content_third{
    flex-direction: row;
    justify-content: flex-end;
    padding-bottom: 2ss0px;
    border-bottom-style: solid;
    border-bottom-color: #eee;
    border-bottom-width: 1px;
}
.wxc_button_third {
    border-style: solid;
    border-width: 2px;
    /*border-color: #f2061a;*/
    border-radius: 5px;
    width: 200px;
    margin-right: 20px;
}
.list_content_two1{
    color: #666;
    font-size: 30px;
    padding-left: 10px;
    padding-right: 10px;
}
.list_content_third_price{
    font-size: 40px;
    color: #ff2d2d;
    margin-left: 20px;
    margin-right: 40px;
}

.item-container {
    width: 750px;
    background-color: #f2f3f4;
    padding: 20px;
}
.no-order {
    justify-content: center;
    align-items: center;
    height: 1034px;
    width: 750px;
}
</style>
